Skip to content

Fix silent brute force fallback at aligned vector dimensions - #2483

Open
imotov wants to merge 2 commits into
NVIDIA:mainfrom
imotov:issue-2482-fix-cagra-padded-dataset-flush
Open

Fix silent brute force fallback at aligned vector dimensions#2483
imotov wants to merge 2 commits into
NVIDIA:mainfrom
imotov:issue-2482-fix-cagra-padded-dataset-flush

Conversation

@imotov

@imotov imotov commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

cuvsDatasetMakePadded rejects a device matrix already at CAGRA's required stride, so every field whose dimension is a multiple of four failed its CAGRA build and was silently indexed as brute force. Pick the factory that matches the layout, and log the fallback so the next one is visible.

See #2482

cuvsDatasetMakePadded rejects a device matrix already at CAGRA's required
stride, so every field whose dimension is a multiple of four failed its CAGRA
build and was silently indexed as brute force. Pick the factory that matches
the layout, and log the fallback so the next one is visible.

See NVIDIA#2482
@imotov
imotov requested a review from a team as a code owner August 18, 2026 20:57
@copy-pr-bot

copy-pr-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@imotov imotov self-assigned this Aug 18, 2026
@imotov imotov added Java bug Something isn't working non-breaking Introduces a non-breaking change Lucene labels Aug 18, 2026
@imotov

imotov commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test c87fcd4

Comment on lines +210 to +216
info(
infoStream,
COMPONENT,
"CAGRA build failed for field \""
+ fieldInfo.name
+ "\", falling back to a brute force index: "
+ t);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mythrocks

Copy link
Copy Markdown
Contributor

I see what you're doing here; I'm generally 👍.

But I think what you've mentioned in #2482 is a serious point: It does feel like there is room to iron out the API a little better. Leaving it to the caller to remember to call isPaddedDataset() isn't completely foolproof. For instance:

  1. This fix seems geared towards cuvs-lucene working properly. Since we haven't changed the C-API at all, your Python example is still vulnerable to breakage, unless I'm mistaken.
  2. All future Java call sites will have to repeat the pattern we have established here.

We can check this in now. But I'm wondering if we should consider a more foolproof approach in the future.

I toyed with the idea of making CuVSMatrix etc. a reference counted Closeable:

  1. Every time the instance is copied, we increase the reference count.
  2. Every time it's closed, we decrement the reference count.
  3. Once it is closed for the last time, the reference count goes to 0. That's when it's actually closed.

This will allow us to have makePaddedDatasetView(dataset) return a Tuple< CuVSMatrix, View >:

  1. If already padded, return the argument dataset and a view into it.
  2. If not padded, return a copied, padded dataset and a view to that.
    In both cases, both returns are handled with try-with-resources. They are closed on end of scope.

The consumption code would look something like:

      var tuple = index.makePaddedDatasetView(deviceVectors);
      try (
        var dataset = tuple.first();
        var view    = tuple.second()
      ) {
        index.updateDataset(view);
        index.serialize(os);
      }

Does something like that make sense for the future?

@mythrocks mythrocks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally 👍. A design consideration suggested for the future.

@imotov

imotov commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2cb1b39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Java Lucene non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants